package com.hyh.admin.sys.controller.mail;

import cn.hutool.extra.mail.MailUtil;
import com.hyh.ad.common.core.domain.AjaxResult;
import com.hyh.admin.tool.EmailUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/mail")
@Api(tags = "邮件操作处理")
public class MailController {
    @Autowired
    private EmailUtil mailUtil;

    /**
     * @param email
     * @return
     */
    @PostMapping("/send")
    @ApiOperation("发送邮件")
    public AjaxResult sendMail(@RequestParam("email") String email) throws Exception {
        boolean flag = mailUtil.sendMail(email);
        if (flag) {
            return AjaxResult.success(true);
        } else {
            return AjaxResult.error("发送失败");
        }
    }
}
